package com.vvlive.caibao.smartcity.ui;

import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.vvlive.caibao.smartcity.app.SmartCityApp;
import com.vvlive.caibao.smartcity.base.BaseActivity;
import com.vvlive.caibao.smartcity.bean.Person;
import com.vvlive.caibao.smartcity.utils.GsonUtil;
import com.vvlive.caibao.smartcity.utils.QRImageUtil;
import com.vvlive.caibao.smartcity.utils.ScreenUtil;
import com.vvlive.caibao.smartcity.view.CommonActionBar;

import smartcity.vvlive.caibao.com.smartc.R;

/**
 * Created by zhj on 2015/11/24.
 * 扫描二维码名片
 */
public class QRCodeActivity extends BaseActivity {

    private ImageView mImage;
    private Button mScan;

    @Override
    protected int getContentViewRes() {
        return R.layout.activity_qr_code;
    }

    @Override
    public void initWidget() {

        CommonActionBar actionBar = getCommonActionBar();
        actionBar.setTitle(R.string.func_qr_card);
        actionBar.setMoreVisible(false);

        mImage = (ImageView) findViewById(R.id.qr_code_image);
        mImage.setLayoutParams(new LinearLayout.LayoutParams(new ScreenUtil(this).getWidth(), new ScreenUtil(this).getWidth()));

        Person person = new Person(SmartCityApp.currentUser.getObjectId(),
                                          "http://f.hiphotos.baidu.com/image/h%3D300/sign=77e67f60ef50352aae6123086342fb1a/f11f3a292df5e0fed430f9d65a6034a85edf7238.jpg",
                                          1, "A0001", "IT研发部", "软件工程师", "13122222222");
        Bitmap bitmap = QRImageUtil.createQRImage(GsonUtil.toJson(person));
        mImage.setImageBitmap(bitmap);

        mScan = (Button) findViewById(R.id.qr_scan);
        mScan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 扫描二维码
                newActivity(CaptureActivity.class);
            }
        });

    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    }
}
